package com.briup.framework.utils.web;

/**
 * @author guomiao
 *
 * @Date 2022/3/3 14:53
 */
public class Response<T>{
    private Integer code;
    private String status;
    private String message;
    private T data;

    public Response() {
    }

    public Response(T data) {
        this.code = ResponseCode.SUCCESS.getCode();
        this.status = ResponseCode.SUCCESS.getStatus();
        this.message = "成功";
        this.data = data;
    }

    public Response(Integer code, String status, String message) {
        this.code = code;
        this.status = status;
        this.message = message;
    }

    public static <T> Response<T> success(T data) {
        return new Response<T>(data);
    }

    public static <String> Response<String> success() {
        return new Response("操作成功");
    }

    public static Response error(ResponseCode responseCode, String message) {
        return new Response(responseCode.getCode(), responseCode.getStatus(), message);
    }

    public static Response error(Integer code, String status, String message) {
        return new Response(code, status, message);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Response{" +
                "code=" + code +
                ", status='" + status + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
